package com.java1412.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author java1412
 * @since 2023-08-11 09:24:10
 */
@Data
@Component
@ConfigurationProperties(prefix = "alipay")
public class AlipayConfig {

    private String appId;
    private String appPrivateKey;
    private String alipayPublicKey;
    private String notifyUrl;

    @PostConstruct
    public void init() {
        // 设置参数(全局设置，只需要设置一次)
        Config config = new Config();
        config.protocol = "https"; // 设置协议
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com"; // 设置支付网关
        config.signType = "RSA2"; // 设置加密方式/签名方式
        config.appId = this.appId; // 设置应用id
        config.merchantPrivateKey = this.appPrivateKey; // 设置应用私钥
        config.alipayPublicKey = this.alipayPublicKey; // 设置支付公钥
        config.notifyUrl = this.notifyUrl; // 设置支付成功时的回调地址
        Factory.setOptions(config);
        System.out.println("=============支付宝SDK初始化成功==============");
    }
}
